/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import modelo.HistorialVenta;
import modelo.Venta;

/**
 *
 * @author Cristian Perez
 */
public class HistorialVentasDao {
    private static HistorialVentasDao instance = null;

    public HistorialVentasDao() {
        //Instanciacion de Singleton
    }

    public static HistorialVentasDao getInstance() {
        if (instance == null) {
            instance = new HistorialVentasDao();
        }
        return instance;
    }

    public void agregar(Connection c, ArrayList lista) throws SQLException {
        Statement stmt = null;
        try {
            Iterator iteraLista = lista.iterator();
            while (iteraLista.hasNext()) {
                Venta vent = (Venta) iteraLista.next();
                String query = "INSERT INTO historialventas (usr, idArt, cantidad, fecha, total) VALUES ('"+vent.getUsr().getNombreUsuario()+"','"+vent.getArt().getCod()+"','"+vent.getCantidad()+"','"+vent.getFecha()+"','"+vent.getTotal()+"')";
                stmt = c.createStatement();
                stmt.execute(query);
            }
        }catch(Exception e) {e.printStackTrace(); stmt.close();}
    }
}
